package se.vgregion.icc;

import java.util.HashMap;
import java.util.Map;

import se.vgregion.icc.handlers.ResponseHandler;

/***
 * Registry class to hold instances of response handlers.
 * 
 * @author ricra2 & andan40
 * @see {@link se.vgregion.icc.handlers.ResponseHandler}
 */
public final class ResponseHandlerRegistry {
    private Map<String, ResponseHandler> responseHandler;

    private ResponseHandlerRegistry() {
        responseHandler = new HashMap<String, ResponseHandler>();
    }

    /***
     * Returns an ResponseHandler implementation based on what xml tagname
     * that needs to be handled.
     * 
     * @param handleClassByTag Name of the xml tag for the class name.
     * @return An PingHandler implementation.
     */
    public ResponseHandler getResponseHandler(String handleClassByTag) {
        return responseHandler.get(handleClassByTag);
    }

    /***
     * Register the ResponseHandler and the name of the class it can handle.
     * 
     * @param handleClassByTag the class the implementation can handle, this will become the HashMap key.
     * @param implementation the implemented class you want to add
     */
    public void addPingHandlerImplementation(String handleClassByTag, ResponseHandler implementation) {
        responseHandler.put(handleClassByTag, implementation);
    }
}
